<?php

class Soul_Language_Translator{
	
	public static $languages = array();

    public function __construct(){}
  
    public function __($key) {
        $arr = explode('.', $key);
        $result = self::$languages;
        foreach($arr as $key){
            if(!is_array($result)){
                return '';
            }
            $result = isset($result[$key])? $result[$key]: NULL;
        }
//        switch(count($arr)){
//        	case 1:
//        		return self::$languages[$arr[0]];
//        	case 2:
//        		return self::$languages[$arr[0]][$arr[1]];
//        	case 3:
//        		return self::$languages[$arr[0]][$arr[1]][$arr[2]];
//        	case 4:
//        		return self::$languages[$arr[0]][$arr[1]][$arr[2]][$arr[3]]; 
//        	case 5:
//        		return self::$languages[$arr[0]][$arr[1]][$arr[2]][$arr[3]][$arr[4]];
//        	case 6:
//        		return self::$languages[$arr[0]][$arr[1]][$arr[2]][$arr[3]][$arr[4]][$arr[5]];        		        		        		
//        }
        return $result;
    }

    public function __f() {
        $args = func_get_args();
        if(is_array($args[0])){
            $args = $args[0];
        }
        $args[0] = self::__($args[0]);
        for ($i = 1; $i < count($args); $i++) {
            if ($args[$i][0] == '{' && substr($args[$i], -1) == '}') {
                $args[$i] = $this->__(substr($args[$i], 1, -1));
            }
        }
        return call_user_func_array('sprintf', $args);
    }
}